﻿#include <windows.h>
#include"resource.h"
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>

struct node{
	int inf;
};

struct el_lista_noduri{
	node N;
	el_lista_noduri *next;
	struct el_lista_noduri *child[8];
};

el_lista_noduri *head=NULL;
el_lista_noduri *root=NULL;

HWND d1=NULL;
HDC hDC;
    PAINTSTRUCT Ps;
	COLORREF clrRed  = RGB(255, 25, 5);
	COLORREF clrAqua = RGB(0, 255, 255);
	COLORREF clrNavy = RGB(0, 0, 128);
    POINT Pt[365];
	DWORD  lpPts[] = { 5, 5,5,5,5,5,5,5,5,5,5, 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5
	,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5};
void desenare(HWND hwnd,int n)
{
	
	for(int i=0;i<n;i++)
	{
		if(i==0)
		{
			Pt[0].x = 635; Pt[0].y = 10;
			Pt[1].x = 665; Pt[1].y = 10;
			Pt[2].x = 665; Pt[2].y = 40;
			Pt[3].x = 635; Pt[3].y = 40;
			Pt[4].x = 635; Pt[4].y = 10;
		}
		if(i==1)
		{
    
			Pt[5].x = 117;  Pt[5].y = 150;
			Pt[6].x = 147; Pt[6].y = 150;
			Pt[7].x = 147; Pt[7].y = 180;
			Pt[8].x = 117; Pt[8].y = 180;
			Pt[9].x = 117; Pt[9].y = 150;
		}
		if(i==2)
		{
			Pt[10].x = 264;  Pt[10].y = 150;
			Pt[11].x = 294; Pt[11].y = 150;
			Pt[12].x = 294; Pt[12].y = 180;
			Pt[13].x = 264; Pt[13].y = 180;
			Pt[14].x = 264; Pt[14].y = 150;
			
		}
		if(i==3)
			{
			Pt[15].x = 411;  Pt[15].y = 150;
			Pt[16].x = 441; Pt[16].y = 150;
			Pt[17].x = 441; Pt[17].y = 180;
			Pt[18].x = 411; Pt[18].y = 180;
			Pt[19].x = 411; Pt[19].y = 150;
			}
		if(i==4)
			{

			Pt[20].x = 558;  Pt[20].y = 150;
			Pt[21].x = 588; Pt[21].y = 150;
			Pt[22].x = 588; Pt[22].y = 180;
			Pt[23].x = 558; Pt[23].y = 180;
			Pt[24].x = 558; Pt[24].y = 150;
			}

		if(i==5)
		{
			Pt[25].x = 705;  Pt[25].y = 150;
			Pt[26].x = 735; Pt[26].y = 150;
			Pt[27].x = 735; Pt[27].y = 180;
			Pt[28].x = 705; Pt[28].y = 180;
			Pt[29].x = 705; Pt[29].y = 150;
		}
		if(i==6)
		{

			Pt[30].x = 852;  Pt[30].y = 150;
			Pt[31].x = 882; Pt[31].y = 150;
			Pt[32].x = 882; Pt[32].y = 180;
			Pt[33].x = 852; Pt[33].y = 180;
			Pt[34].x = 852; Pt[34].y = 150;
		}
		if(i==7)
		{
	
			Pt[35].x = 999;  Pt[35].y = 150;
			Pt[36].x = 1029; Pt[36].y = 150;
			Pt[37].x = 1029; Pt[37].y = 180;
			Pt[38].x = 999; Pt[38].y = 180;
			Pt[39].x = 999; Pt[39].y = 150;
		}

		if(i==8)
		{
			Pt[40].x = 1146;  Pt[40].y = 150;
			Pt[41].x = 1176; Pt[41].y = 150;
			Pt[42].x = 1176; Pt[42].y = 180;
			Pt[43].x = 1146; Pt[43].y = 180;
			Pt[44].x = 1146; Pt[44].y = 150;
		}
		if(i==9)
		{

			Pt[45].x = 5;  Pt[45].y = 290;
			Pt[46].x = 20; Pt[46].y = 290;
			Pt[47].x = 20; Pt[47].y = 305;
			Pt[48].x = 5; Pt[48].y = 305;
			Pt[49].x = 5; Pt[49].y = 290;
		}
		if(i==10)
		{
			Pt[50].x = 25;  Pt[50].y = 290;
			Pt[51].x = 40; Pt[51].y = 290;
			Pt[52].x = 40; Pt[52].y = 305;
			Pt[53].x = 25; Pt[53].y = 305;
			Pt[54].x = 25; Pt[54].y = 290;
		}
		if(i==11)
		{

			Pt[55].x = 45;  Pt[55].y = 290;
			Pt[56].x = 60; Pt[56].y = 290;
			Pt[57].x = 60; Pt[57].y = 305;
			Pt[58].x = 45; Pt[58].y = 305;
			Pt[59].x = 45; Pt[59].y = 290;
		}
		if(i==12)
		{

			Pt[60].x = 65;  Pt[60].y = 290;
			Pt[61].x = 80; Pt[61].y = 290;
			Pt[62].x = 80; Pt[62].y = 305;
			Pt[63].x = 65; Pt[63].y = 305;
			Pt[64].x = 65; Pt[64].y = 290;
		}
		if(i==13)
		{

			Pt[65].x = 85;  Pt[65].y = 290;
			Pt[66].x = 100; Pt[66].y = 290;
			Pt[67].x = 100; Pt[67].y = 305;
			Pt[68].x = 85; Pt[68].y = 305;
			Pt[69].x = 85; Pt[69].y = 290;
		}
		if(i==14)
		{
			Pt[70].x = 105;  Pt[70].y = 290;
			Pt[71].x = 120; Pt[71].y = 290;
			Pt[72].x = 120; Pt[72].y = 305;
			Pt[73].x = 105; Pt[73].y = 305;
			Pt[74].x = 105; Pt[74].y = 290;
		}
		if(i==15)
		{

			Pt[75].x = 125;  Pt[75].y = 290;
			Pt[76].x = 140; Pt[76].y = 290;
			Pt[77].x = 140; Pt[77].y = 305;
			Pt[78].x = 125; Pt[78].y = 305;
			Pt[79].x = 125; Pt[79].y = 290;
		}
		if(i==16)
		{

			Pt[80].x = 145;  Pt[80].y = 290;
			Pt[81].x = 160; Pt[81].y = 290;
			Pt[82].x = 160; Pt[82].y = 305;
			Pt[83].x = 145; Pt[83].y = 305;
			Pt[84].x = 145; Pt[84].y = 290;
		}
		if(i==17)
		{

			Pt[85].x = 165;  Pt[85].y = 290;
			Pt[86].x = 180; Pt[86].y = 290;
			Pt[87].x = 180; Pt[87].y = 305;
			Pt[88].x = 165; Pt[88].y = 305;
			Pt[89].x = 165; Pt[89].y = 290;
		}
		if(i==18)
		{
			Pt[90].x = 185;  Pt[90].y = 290;
			Pt[91].x = 200; Pt[91].y = 290;
			Pt[92].x = 200; Pt[92].y = 305;
			Pt[93].x = 185; Pt[93].y = 305;
			Pt[94].x = 185; Pt[94].y = 290;
		}
		if(i==19)
		{
			Pt[95].x = 205;  Pt[95].y = 290;
			Pt[96].x = 220; Pt[96].y = 290;
			Pt[97].x = 220; Pt[97].y = 305;
			Pt[98].x = 205; Pt[98].y = 305;
			Pt[99].x = 205; Pt[99].y = 290;
		}
		if(i==20)
		{

			Pt[100].x = 225;  Pt[100].y = 290;
			Pt[101].x = 240; Pt[101].y = 290;
			Pt[102].x = 240; Pt[102].y = 305;
			Pt[103].x = 225; Pt[103].y = 305;
			Pt[104].x = 225; Pt[104].y = 290;
		}
		if(i==21)
		{

			Pt[105].x = 245;  Pt[105].y = 290;
			Pt[106].x = 260; Pt[106].y = 290;
			Pt[107].x = 260; Pt[107].y = 305;
			Pt[108].x = 245; Pt[108].y = 305;
			Pt[109].x = 245; Pt[109].y = 290;
		}
		if(i==22)
		{

			Pt[110].x = 265;  Pt[110].y = 290;
			Pt[111].x = 280; Pt[111].y = 290;
			Pt[112].x = 280; Pt[112].y = 305;
			Pt[113].x = 265; Pt[113].y = 305;
			Pt[114].x = 265; Pt[114].y = 290;
		}
		if(i==23)
		{

			Pt[115].x = 285;  Pt[115].y = 290;
			Pt[116].x = 300; Pt[116].y = 290;
			Pt[117].x = 300; Pt[117].y = 305;
			Pt[118].x = 285; Pt[118].y = 305;
			Pt[119].x = 285; Pt[119].y = 290;
		}
		if(i==24)
		{

			Pt[120].x = 305;  Pt[120].y = 290;
			Pt[121].x = 320; Pt[121].y = 290;
			Pt[122].x = 320; Pt[122].y = 305;
			Pt[123].x = 305; Pt[123].y = 305;
			Pt[124].x = 305; Pt[124].y = 290;
		}
		if(i==25)
		{

			Pt[125].x = 325;  Pt[125].y = 290;
			Pt[126].x = 340; Pt[126].y = 290;
			Pt[127].x = 340; Pt[127].y = 305;
			Pt[128].x = 325; Pt[128].y = 305;
			Pt[129].x = 325; Pt[129].y = 290;
		}
		if(i==26)
		{

			Pt[130].x = 345;  Pt[130].y = 290;
			Pt[131].x = 360; Pt[131].y = 290;
			Pt[132].x = 360; Pt[132].y = 305;
			Pt[133].x = 345; Pt[133].y = 305;
			Pt[134].x = 345; Pt[134].y = 290;
		}
		if(i==27)
		{
			Pt[135].x = 365;  Pt[135].y = 290;
			Pt[136].x = 380; Pt[136].y = 290;
			Pt[137].x = 380; Pt[137].y = 305;
			Pt[138].x = 365; Pt[138].y = 305;
			Pt[139].x = 365; Pt[139].y = 290;
		}
		if(i==28)
		{
			Pt[140].x = 385;  Pt[140].y = 290;
			Pt[141].x = 400; Pt[141].y = 290;
			Pt[142].x = 400; Pt[142].y = 305;
			Pt[143].x = 385; Pt[143].y = 305;
			Pt[144].x = 385; Pt[144].y = 290;
		}
		if(i==29)
		{

			Pt[145].x = 405;  Pt[145].y = 290;
			Pt[146].x = 420; Pt[146].y = 290;
			Pt[147].x = 420; Pt[147].y = 305;
			Pt[148].x = 405; Pt[148].y = 305;
			Pt[149].x = 405; Pt[149].y = 290;
		}
		if(i==30)
		{

			Pt[150].x = 425;  Pt[150].y = 290;
			Pt[151].x = 440; Pt[151].y = 290;
			Pt[152].x = 440; Pt[152].y = 305;
			Pt[153].x = 425; Pt[153].y = 305;
			Pt[154].x = 425; Pt[154].y = 290;
		}
		if(i==31)
		{
			Pt[155].x = 445;  Pt[155].y = 290;
			Pt[156].x = 460; Pt[156].y = 290;
			Pt[157].x = 460; Pt[157].y = 305;
			Pt[158].x = 445; Pt[158].y = 305;
			Pt[159].x = 445; Pt[159].y = 290;
		}
		if(i==32)
		{
			Pt[160].x = 465;  Pt[160].y = 290;
			Pt[161].x = 480; Pt[161].y = 290;
			Pt[162].x = 480; Pt[162].y = 305;
			Pt[163].x = 465; Pt[163].y = 305;
			Pt[164].x = 465; Pt[164].y = 290;
		}
		if(i==33)
		{
			Pt[165].x = 485;  Pt[165].y = 290;
			Pt[166].x = 500; Pt[166].y = 290;
			Pt[167].x = 500; Pt[167].y = 305;
			Pt[168].x = 485; Pt[168].y = 305;
			Pt[169].x = 485; Pt[169].y = 290;
		}
		if(i==34)
		{

			Pt[170].x = 505;  Pt[170].y = 290;
			Pt[171].x = 520; Pt[171].y = 290;
			Pt[172].x = 520; Pt[172].y = 305;
			Pt[173].x = 505; Pt[173].y = 305;
			Pt[174].x = 505; Pt[174].y = 290;
		}
		if(i==35)
		{
			Pt[175].x = 525;  Pt[175].y = 290;
			Pt[176].x = 540; Pt[176].y = 290;
			Pt[177].x = 540; Pt[177].y = 305;
			Pt[178].x = 525; Pt[178].y = 305;
			Pt[179].x = 525; Pt[179].y = 290;
		}
		if(i==36)
		{
			Pt[180].x = 545;  Pt[180].y = 290;
			Pt[181].x = 560; Pt[181].y = 290;
			Pt[182].x = 560; Pt[182].y = 305;
			Pt[183].x = 545; Pt[183].y = 305;
			Pt[184].x = 545; Pt[184].y = 290;
		}
		if(i==37)
		{
			Pt[185].x = 565;  Pt[185].y = 290;
			Pt[186].x = 580; Pt[186].y = 290;
			Pt[187].x = 580; Pt[187].y = 305;
			Pt[188].x = 565; Pt[188].y = 305;
			Pt[189].x = 565; Pt[189].y = 290;
		}
		if(i==38)
		{

			Pt[190].x = 585;  Pt[190].y = 290;
			Pt[191].x = 600; Pt[191].y = 290;
			Pt[192].x = 600; Pt[192].y = 305;
			Pt[193].x = 585; Pt[193].y = 305;
			Pt[194].x = 585; Pt[194].y = 290;
		}
		if(i==39)
		{

			Pt[195].x = 605;  Pt[195].y = 290;
			Pt[196].x = 620; Pt[196].y = 290;
			Pt[197].x = 620; Pt[197].y = 305;
			Pt[198].x = 605; Pt[198].y = 305;
			Pt[199].x = 605; Pt[199].y = 290;
		}
		if(i==40)
		{
			Pt[200].x = 625;  Pt[200].y = 290;
			Pt[201].x = 640; Pt[201].y = 290;
			Pt[202].x = 640; Pt[202].y = 305;
			Pt[203].x = 625; Pt[203].y = 305;
			Pt[204].x = 625; Pt[204].y = 290;
		}
		if(i==41)
		{

			Pt[205].x = 645;  Pt[205].y = 290;
			Pt[206].x = 660; Pt[206].y = 290;
			Pt[207].x = 660; Pt[207].y = 305;
			Pt[208].x = 645; Pt[208].y = 305;
			Pt[209].x = 645; Pt[209].y = 290;
		}

		if(i==42)
		{
			Pt[210].x = 665;  Pt[210].y = 290;
			Pt[211].x = 680; Pt[211].y = 290;
			Pt[212].x = 680; Pt[212].y = 305;
			Pt[213].x = 665; Pt[213].y = 305;
			Pt[214].x = 665; Pt[214].y = 290;
		}
		if(i==43)
		{
			Pt[215].x = 685;  Pt[215].y = 290;
			Pt[216].x = 700; Pt[216].y = 290;
			Pt[217].x = 700; Pt[217].y = 305;
			Pt[218].x = 685; Pt[218].y = 305;
			Pt[219].x = 685; Pt[219].y = 290;
		}
		if(i==44)
		{
			Pt[220].x = 705;  Pt[220].y = 290;
			Pt[221].x = 720; Pt[221].y = 290;
			Pt[222].x = 720; Pt[222].y = 305;
			Pt[223].x = 705; Pt[223].y = 305;
			Pt[224].x = 705; Pt[224].y = 290;
		}
		if(i==45)
		{
			Pt[225].x = 725;  Pt[225].y = 290;
			Pt[226].x = 740; Pt[226].y = 290;
			Pt[227].x = 740; Pt[227].y = 305;
			Pt[228].x = 725; Pt[228].y = 305;
			Pt[229].x = 725; Pt[229].y = 290;
		}
		if(i==46)
		{
			Pt[230].x = 745;  Pt[230].y = 290;
			Pt[231].x = 760; Pt[231].y = 290;
			Pt[232].x = 760; Pt[232].y = 305;
			Pt[233].x = 745; Pt[233].y = 305;
			Pt[234].x = 745; Pt[234].y = 290;
		}
		if(i==47)
		{
			Pt[235].x = 765;  Pt[235].y = 290;
			Pt[236].x = 780; Pt[236].y = 290;
			Pt[237].x = 780; Pt[237].y = 305;
			Pt[238].x = 765; Pt[238].y = 305;
			Pt[239].x = 765; Pt[239].y = 290;
		}
		if(i==48)
		{

			Pt[240].x = 785;  Pt[240].y = 290;
			Pt[241].x = 800; Pt[241].y = 290;
			Pt[242].x = 800; Pt[242].y = 305;
			Pt[243].x = 785; Pt[243].y = 305;
			Pt[244].x = 785; Pt[244].y = 290;
		}
		if(i==49)
		{
			Pt[245].x = 805;  Pt[245].y = 290;
			Pt[246].x = 820; Pt[246].y = 290;
			Pt[247].x = 820; Pt[247].y = 305;
			Pt[248].x = 805; Pt[248].y = 305;
			Pt[249].x = 805; Pt[249].y = 290;
		}
		if(i==50)
		{
			Pt[250].x = 825;  Pt[250].y = 290;
			Pt[251].x = 840; Pt[251].y = 290;
			Pt[252].x = 840; Pt[252].y = 305;
			Pt[253].x = 825; Pt[253].y = 305;
			Pt[254].x = 825; Pt[254].y = 290;
		}
		if(i==51)
		{
			Pt[255].x = 845;  Pt[255].y = 290;
			Pt[256].x = 860; Pt[256].y = 290;
			Pt[257].x = 860; Pt[257].y = 305;
			Pt[258].x = 845; Pt[258].y = 305;
			Pt[259].x = 845; Pt[259].y = 290;
		}
		if(i==52)
		{
			Pt[260].x = 865;  Pt[260].y = 290;
			Pt[261].x = 880; Pt[261].y = 290;
			Pt[262].x = 880; Pt[262].y = 305;
			Pt[263].x = 865; Pt[263].y = 305;
			Pt[264].x = 865; Pt[264].y = 290;
		}
		if(i==53)
		{
			Pt[265].x = 885;  Pt[265].y = 290;
			Pt[266].x = 900; Pt[266].y = 290;
			Pt[267].x = 900; Pt[267].y = 305;
			Pt[268].x = 885; Pt[268].y = 305;
			Pt[269].x = 885; Pt[269].y = 290;
		}
		if(i==54)
		{
			Pt[270].x = 905;  Pt[270].y = 290;
			Pt[271].x = 920; Pt[271].y = 290;
			Pt[272].x = 920; Pt[272].y = 305;
			Pt[273].x = 905; Pt[273].y = 305;
			Pt[274].x = 905; Pt[274].y = 290;
		}
		if(i==55)
		{
			Pt[275].x = 925;  Pt[275].y = 290;
			Pt[276].x = 940; Pt[276].y = 290;
			Pt[277].x = 940; Pt[277].y = 305;
			Pt[278].x = 925; Pt[278].y = 305;
			Pt[279].x = 925; Pt[279].y = 290;
		}
		if(i==56)
		{
			Pt[280].x = 945;  Pt[280].y = 290;
			Pt[281].x = 960; Pt[281].y = 290;
			Pt[282].x = 960; Pt[282].y = 305;
			Pt[283].x = 945; Pt[283].y = 305;
			Pt[284].x = 945; Pt[284].y = 290;
		}
		if(i==57)
		{

			Pt[285].x = 965;  Pt[285].y = 290;
			Pt[286].x = 980; Pt[286].y = 290;
			Pt[287].x = 980; Pt[287].y = 305;
			Pt[288].x = 965; Pt[288].y = 305;
			Pt[289].x = 965; Pt[289].y = 290;
		}
		if(i==58)
		{
			Pt[290].x = 985;  Pt[290].y = 290;
			Pt[291].x = 1000; Pt[291].y = 290;
			Pt[292].x = 1000; Pt[292].y = 305;
			Pt[293].x = 985; Pt[293].y = 305;
			Pt[294].x = 985; Pt[294].y = 290;
		}
		if(i==59)
		{
			Pt[295].x = 1005;  Pt[295].y = 290;
			Pt[296].x = 1020; Pt[296].y = 290;
			Pt[297].x = 1020; Pt[297].y = 305;
			Pt[298].x = 1005; Pt[298].y = 305;
			Pt[299].x = 1005; Pt[299].y = 290;
		}
		if(i==60)
		{
			Pt[300].x = 1025;  Pt[300].y = 290;
			Pt[301].x = 1040; Pt[301].y = 290;
			Pt[302].x = 1040; Pt[302].y = 305;
			Pt[303].x = 1025; Pt[303].y = 305;
			Pt[304].x = 1025; Pt[304].y = 290;
		}
		if(i==61)
		{
			Pt[305].x = 1045;  Pt[305].y = 290;
			Pt[306].x = 1060; Pt[306].y = 290;
			Pt[307].x = 1060; Pt[307].y = 305;
			Pt[308].x = 1045; Pt[308].y = 305;
			Pt[309].x = 1045; Pt[309].y = 290;
		}
		if(i==62)
		{
			Pt[310].x = 1065;  Pt[310].y = 290;
			Pt[311].x = 1080; Pt[311].y = 290;
			Pt[312].x = 1080; Pt[312].y = 305;
			Pt[313].x = 1065; Pt[313].y = 305;
			Pt[314].x = 1065; Pt[314].y = 290;
		}
		if(i==63)
		{
			Pt[315].x = 1085;  Pt[315].y = 290;
			Pt[316].x = 1100; Pt[316].y = 290;
			Pt[317].x = 1100; Pt[317].y = 305;
			Pt[318].x = 1085; Pt[318].y = 305;
			Pt[319].x = 1085; Pt[319].y = 290;
		}
		if(i==64)
		{
			Pt[320].x = 1105;  Pt[320].y = 290;
			Pt[321].x = 1120; Pt[321].y = 290;
			Pt[322].x = 1120; Pt[322].y = 305;
			Pt[323].x = 1105; Pt[323].y = 305;
			Pt[324].x = 1105; Pt[324].y = 290;
		}
		if(i==65)
		{
			Pt[325].x = 1125;  Pt[325].y = 290;
			Pt[326].x = 1140; Pt[326].y = 290;
			Pt[327].x = 1140; Pt[327].y = 305;
			Pt[328].x = 1125; Pt[328].y = 305;
			Pt[329].x = 1125; Pt[329].y = 290;
		}
		if(i==66)
		{
			Pt[330].x = 1145;  Pt[330].y = 290;
			Pt[331].x = 1160; Pt[331].y = 290;
			Pt[332].x = 1160; Pt[332].y = 305;
			Pt[333].x = 1145; Pt[333].y = 305;
			Pt[334].x = 1145; Pt[334].y = 290;
		}
		if(i==67)
		{
			Pt[335].x = 1165;  Pt[335].y = 290;
			Pt[336].x = 1180; Pt[336].y = 290;
			Pt[337].x = 1180; Pt[337].y = 305;
			Pt[338].x = 1165; Pt[338].y = 305;
			Pt[339].x = 1165; Pt[339].y = 290;
		}
		if(i==68)
		{

			Pt[340].x = 1185;  Pt[340].y = 290;
			Pt[341].x = 1200; Pt[341].y = 290;
			Pt[342].x = 1200; Pt[342].y = 305;
			Pt[343].x = 1185; Pt[343].y = 305;
			Pt[344].x = 1185; Pt[344].y = 290;
		}
		if(i==69)
		{
			Pt[345].x = 1205;  Pt[345].y = 290;
			Pt[346].x = 1220; Pt[346].y = 290;
			Pt[347].x = 1220; Pt[347].y = 305;
			Pt[348].x = 1205; Pt[348].y = 305;
			Pt[349].x = 1205; Pt[349].y = 290;
		}

		if(i==70)
		{
			Pt[350].x = 1225;  Pt[350].y = 290;
			Pt[351].x = 1240; Pt[351].y = 290;
			Pt[352].x = 1240; Pt[352].y = 305;
			Pt[353].x = 1225; Pt[353].y = 305;
			Pt[354].x = 1225; Pt[354].y = 290;
		}
		if(i==71)
		{
			Pt[355].x = 1245;  Pt[355].y = 290;
			Pt[356].x = 1260; Pt[356].y = 290;
			Pt[357].x = 1260; Pt[357].y = 305;
			Pt[358].x = 1245; Pt[358].y = 305;
			Pt[359].x = 1245; Pt[359].y = 290;
		}
		if(i==72)
		{
			Pt[360].x = 1265;  Pt[360].y = 290;
			Pt[361].x = 1280; Pt[361].y = 290;
			Pt[362].x = 1280; Pt[362].y = 305;
			Pt[363].x = 1265; Pt[363].y = 305;
			Pt[364].x = 1265; Pt[364].y = 290;
		}
	}
}

char *buffer=(char*)malloc(100*sizeof(char));
char *buffer1=(char*)malloc(100*sizeof(char));

void insert(int val)
{
	int i;

	el_lista_noduri *nou,*p;
	nou=(el_lista_noduri*)malloc(sizeof(el_lista_noduri));
	nou->N.inf=val;
	if(head==NULL)
	{
		for(i=0;i<8;i++)
			nou->child[i]=NULL;
		nou->next=NULL;
		head=nou;
	}
	else
		if(nou->N.inf<head->N.inf)
		{
			for(i=0;i<8;i++)
				nou->child[i]=NULL;
			nou->next=head;
			head=nou;
		}
		else
		{
			p=head;
			while((p->next!=NULL)&&(p->next->N.inf<nou->N.inf))
				p=p->next;
			for(i=0;i<8;i++)
				nou->child[i]=NULL;
			nou->next=p->next;
			p->next=nou;
		}
		root=head;
		for(i=0;i<8;i++)
			root->child[i]=NULL;
}
void creare_arbore(el_lista_noduri *&root)
{
	el_lista_noduri *p;
	int i;
	if(head==NULL)
	{
		//MessageBox(d1,"nu exista niciun element de inserat!","nu stiu",MB_OK | MB_ICONINFORMATION);
		return;
	}
	p=head->next;
	while(p!=NULL)
	{
		int contor=0;
		for(i=0;i<8;i++)
			if(p!=NULL && contor!=8)
			{
				root->child[i]=p;
				root->child[i]->N.inf=p->N.inf;
				for(int j=0;j<8;j++)
					root->child[i]->child[j]=NULL;
				p=p->next; 
				contor++;
			}
		if(contor==8)
		{
			for(int k=0;k<8;k++)
				for(int j=0;j<8;j++)
					if(p!=NULL)
					{
						root->child[k]->child[j]=p;
						root->child[k]->child[j]->N.inf=p->N.inf;
						for(int y=0;y<8;y++)
							root->child[k]->child[j]->child[y]=NULL;
						p=p->next;
					}
		}
		
	}
	
	
}
void cautare(int val)
{
	el_lista_noduri *p;
	p=head;
	char *buf1;
	int ok=0,j=0;
	int i=0;
	int m;
	int nr=0;
	creare_arbore(p);
	if(p==NULL)
	{
		MessageBox(d1,"nu exista elemente in arbore","cautare",MB_OK | MB_ICONINFORMATION);
		return;
	}
	if(val<p->N.inf)
	{
		MessageBox(d1,"elementul nu exista in arbore:","cautare",MB_OK | MB_ICONINFORMATION);
		return;
	}
	if(p->N.inf==val)
	{
		MessageBox(d1,"valoarea a fost gasita si se afla pe primul nivel al alborelui este radacina arborelui:","cautare",MB_OK | MB_ICONINFORMATION);
		return;
	}
if(p->next)
	int x=0;
	if(p->child[0]->N.inf<=val && val<=p->child[7]->N.inf)
	{
		for(i=0;i<8;i++)
		{
			if(p->child[i]!=NULL)
			{
				if(p->child[i]->N.inf==val)
				{
					nr++;
					ok=1;
					m=i;
				}
			}
			
		}
		if(ok==0)
			MessageBox(d1,"numarul nu exista in arbore:","cautare",MB_OK | MB_ICONINFORMATION);
		else
		{
			sprintf(buf1,"numarul a fost gasit pe nivelul 1,pozitia:%d si a fost gasit de %d ori:",m+1,nr);
			MessageBox(d1,buf1,"cautare",MB_OK | MB_ICONINFORMATION);
			return;
		}
			
	}
	else
	{
	
		int i=0;
		while(i<8)
		{ 
			int v=0;
			if(p->child[i]->child[0]!=NULL && p->child[i]->child[7]!=NULL)
			{
				if(p->child[i]->child[0]->N.inf<=val && val<=p->child[i]->child[7]->N.inf)
				{
					for(j=0;j<8;j++)
						if(p->child[i]->child[j]!=NULL)
						{
							if(p->child[i]->child[j]->N.inf==val)
							{
								nr++;
								ok=1;
								m=j;
							}
						}
					if(ok==1)
					{
						sprintf(buf1,"numarul a fost gasit de %d pe nivelul doi ca fiind al %d copil",nr,m+1);
					MessageBox(d1,buf1,"cautare",MB_OK | MB_ICONINFORMATION);
						return;
					}
				}
				else
					i++;
		}
		else
		{
			while(v<8)
				{
					if(p->child[i]->child[v]!=NULL)
						if(p->child[i]->child[v]->N.inf==val)
						{
							nr++;
							ok=1;
							m=v;
						}
						v++;
				}
			if(ok==1)
					{
						sprintf(buf1,"numarul a fost gasit de %d pe nivelul doi ca fiind al %d copil",nr,m+1);
						MessageBox(d1,buf1,"cautare",MB_OK | MB_ICONINFORMATION);
						return;
					}
			if(ok==0)
				{
					MessageBox(d1,"numarul nu a fost gasit in arbore:","cautare",MB_OK | MB_ICONINFORMATION);
					return;
				}
		}

	}

}
}
/*void stergere(el_lista_noduri *nod,int val)
{
	el_lista_noduri *ajutor,*q;
	nod=head;
	int ok=0;
	if(nod==NULL)
	{
		printf("arborele nu are niciun element");
		return;
	}
	if(nod->N.inf==val)
	{
		ajutor=nod;
		nod=nod->next;
		free(ajutor);
		ok=1;
	}
	else
	{
		q=nod;
		while(q->next!=NULL && q->next->N.inf!=val)
			q=q->next;
		if(q->N.inf==val)
		{
			ajutor=q;
			q=q->next;
			free(ajutor);
			ok=2;
		}
	}
	if(ok==1)
		{
			creare_arbore(nod);
			return;
		}
	else
		if(ok==2)
		{
			creare_arbore(q);
			return;
		}
		else

		{
			printf("nu a fost gasit elementul pe care dorim sa l stergem,deci arborele ramane neschimbat!");
			return;
		}
}*/
void stergere(int v[],int n,int val)
{
	int nr=0,i;
	for(i=0;i<n;i++)
		if(v[i]==val)
		{
			while(i<n-1)
			{
				v[i]=v[i+1];
				i++;
			}
			nr++;
		}
		//	for(i=0;i<n-nr;i++)
				//printf("%d ",v[i]);
}
void resetare()
{
	el_lista_noduri *p;
	while(head!=NULL)
	{
		p=head;
		head=head->next;
		free(p);
	}
}
int transformare(char a[100])
{
	int b;
	b=atoi(a);
	printf("%d",b);
	return b;
}



const char g_szClassName[] = "myWindowClass";
// functia de creare unei casete de dialog
BOOL CALLBACK dialog1 (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{

       switch (msg)
        {
        case WM_INITDIALOG:
                return TRUE;
                break;
        case WM_COMMAND:
                switch (LOWORD(wParam))
                {
				case ID_INSERT:
					int c;
					GetDlgItemText(hwnd,IDC_EDIT1,buffer,5);
					c=transformare(buffer);
					insert(c);
					creare_arbore(root);
					MessageBox(hwnd,"S-a inserat cu succes","Insert",MB_OK | MB_ICONINFORMATION);
              		break;
				case IDC_cautare:
					int d;
					GetDlgItemText(hwnd,IDC_EDIT1,buffer1,5);
					d=transformare(buffer1);
					cautare(d);
					break;
				case IDC_resetare:
					int k;
					GetDlgItemText(hwnd,IDC_EDIT1,buffer,5);
					resetare();
					MessageBox(hwnd,"Arborele a fost resetat","Resetare",MB_OK | MB_ICONINFORMATION);
					break;
				case IDC_OK:
                        EndDialog(hwnd,0);
                        MessageBox(hwnd,"S-a iesit cu succes","Exit",MB_OK | MB_ICONINFORMATION);
                        break;
               
                }
                break;
                case WM_CLOSE:
                EndDialog(hwnd,0);
                break;
        default:
                return FALSE;
        }
        return TRUE;
}
// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	HWND d1;
    switch(msg)
    {		
			case WM_PAINT:
			if(afis==1 && nou1!=0)
		{hDC = BeginPaint(hwnd, &Ps);
        desenare(hwnd,nr);
		PolyPolyline(hDC, Pt,lpPts, 73);
		for(int i=1;i<nr;i++)
		{MoveToEx(hDC,650,40,NULL);
		 LineTo(hDC,i*117+i*15+(i-1)*15,150);
		}if(nr>7)
		{
		for(int i=0;i<8;i++)
		{for(int j=i*8;j<=(i+1)*8-1;j++)
			{MoveToEx(hDC,(i+1)*117+(i+1)*15+i*15,180,NULL);
					 LineTo(hDC,j*20+12,290);
		}}}
		
		
		SetTextColor(hDC, clrNavy);
		TextOut(hDC, 450, 400, "OCTREES-Atanasescu Robert Anton & Dunareanu Sorin", 49);
         
		
		EndPaint(hwnd, &Ps);
		afis=0;
			}	
			break;
        case WM_CLOSE:
            DestroyWindow(hwnd);
        break;
        case WM_DESTROY:
            PostQuitMessage(0);
        break;
		case WM_COMMAND:
			switch(LOWORD(wParam))
			{
			case ID_FILE_NEW40001:
                        d1=CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_DIALOG1),hwnd,dialog1);
                        if (d1!=NULL)
                        {
                                ShowWindow(d1,SW_SHOW);
                        }
                        else
                        {
                                MessageBox(hwnd,"Eroare la crearea dialogului 1","EROARE",MB_OK | MB_ICONERROR);
                        }
                        break;
			case ID_AJUTOR_DESPRE:
				 MessageBox(hwnd,"Acest proiect a fost facut de catre Atanasescu Robert Anton si Dunareanu Sorin","Ajutor",MB_OK | MB_ICONERROR);
				 break;
			case ID_FILE_EXIT:
				exit(1);
			}
		
		default:
            return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
{
    WNDCLASSEX wc;
    HWND hwnd;
    MSG Msg;

    //Step 1: Registering the Window Class
    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.style         = 0;
    wc.lpfnWndProc   = WndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+10);
    wc.lpszMenuName  = MAKEINTRESOURCE(IDR_MENU1);
    wc.lpszClassName = g_szClassName;
    wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

    if(!RegisterClassEx(&wc))
    {
        MessageBox(NULL, "Window Registration Failed!", "Error!",MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    // Step 2: Creating the Window
    hwnd = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        g_szClassName,
        "arbore",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT, 800, 600,
        NULL, NULL, hInstance, NULL);

    if(hwnd == NULL)
    {
        MessageBox(NULL, "Window Creation Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

    // Step 3: The Message Loop
    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }
    return Msg.wParam;
}